<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>梳碧湖驾校预约管理系统</title><!--test-->
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/verify.css">
    <!-- 最重要样式-->
    <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="shortcut icon" href="images/login/favicon.ico">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!--登录动态特性的js-->
    <script src="js/jquery.validate.min.js"></script>
    <!-- Main File-->
    <script src="js/front.js"></script><![endif]-->
    <script src="js/verify.min.js" type="text/javascript"></script>
    <script>
        $(function(){
            var vcode = false;
            var vo = null;
            $('#code').slideVerify({
                type : 1,		//类型
                vOffset : 5,	//误差量，根据需求自行调整
                barSize : {width:'100%',height:'40px'},
                success : function(obj) {
                    vcode = true;
                    vo = obj;
                },
                error : function() {
                    vcode = false;
                }
            });
            $("#btnLogin").click(function(){
                var uid = $("#uid>input").val();
                var pwd = $("#pwd>input").val();
                var reg = /^[0-9a-zA-Z]{4,8}$/;
                var role = $('input[name="optionsRadios"]:checked').val();

                if(uid){
                    $("#uid").removeClass("has-error");
                    $("#uid").addClass("has-success");
                }else{
                    $("#uid").removeClass("has-success");
                    $("#uid").addClass("has-error");
                    return;
                }
                if(reg.test(pwd)){
                    $("#pwd").removeClass("has-error");
                    $("#pwd").addClass("has-success");
                }else{
                    $("#pwd").removeClass("has-success");
                    $("#pwd").addClass("has-error");
                    return;
                }
                if(role==1){
                    if(vcode){
                        var ps = {
                            username:uid,
                            password:pwd
                        }
                        $.post("http://localhost:8889/admin/login",ps,function(data){
                            if(data){
                                //JSON.stringify() 方法是将一个JavaScript值(对象或者数组)转换为JSON字符串
                                var admin_id = data.id;
                                $.getJSON("http://localhost:8889/admin/find/"+admin_id,function (data) {
                                    var s = JSON.stringify(data[0]);
                                    localStorage.setItem("admin",s);
                                    console.log(s)
                                    location.href = "index.html";
                                })
                                //把数据存储在浏览器里面

                            }else{
                                vcode = false;
                                vo.refresh();
                                $(".msg").text("用户名或密码不正确，请重新输入！");
                                $(".msg").css("color","darkred");
                            }
                        });
                    }
                }else if(role==6){
                    if(vcode){
                        var ps = {
                            username:uid,
                            password:pwd
                        }
                        $.post("http://localhost:8889/student/login",ps,function(data){
                            if(data){
                                var id = data.stuId;
                                var role_id = id.toString();
                                console.log(role_id)
                                var info = {
                                    username:'xueyuan',
                                    password:'123456'
                                }
                                $.post("http://localhost:8889/admin/login",info,function(data){
                                    if(data){
                                        //JSON.stringify() 方法是将一个JavaScript值(对象或者数组)转换为JSON字符串
                                        var admin_id = data.id;
                                        $.getJSON("http://localhost:8889/admin/find/"+admin_id,function (data) {
                                            var s = JSON.stringify(data[0]);
                                            localStorage.setItem("admin",s);
                                            localStorage.setItem("role_id",role_id);
                                            location.href = "index.html";
                                        })
                                        //把数据存储在浏览器里面


                                    }else{
                                        vcode = false;
                                        vo.refresh();
                                        $(".msg").text("用户名或密码不正确，请重新输入！");
                                        $(".msg").css("color","darkred");
                                    }
                                });
                            }else{
                                vcode = false;
                                vo.refresh();
                                $(".msg").text("用户名或密码不正确，请重新输入！");
                                $(".msg").css("color","darkred");
                            }
                        })

                    }


                }else if(role==7){

                    if(vcode){
                        var ps = {
                            username:uid,
                            password:pwd
                        }
                        $.post("http://localhost:8889/coach/login",ps,function(data){
                            if(data){
                                var id = data.coaId;
                                var role_id = id.toString();
                                console.log(role_id)
                                console.log(data)
                                var info = {
                                    username:'jiaolian',
                                    password:'123456'
                                }
                                $.post("http://localhost:8889/admin/login",info,function(data){
                                    if(data){
                                        //JSON.stringify() 方法是将一个JavaScript值(对象或者数组)转换为JSON字符串
                                        var admin_id = data.id;
                                        $.getJSON("http://localhost:8889/admin/find/"+admin_id,function (data) {
                                            var s = JSON.stringify(data[0]);
                                            localStorage.setItem("admin",s);
                                            localStorage.setItem("role_id",role_id);
                                            console.log(s)
                                            location.href = "reverses.html";
                                        })
                                        //把数据存储在浏览器里面

                                    }else{
                                        vcode = false;
                                        vo.refresh();
                                        $(".msg").text("用户名或密码不正确，请重新输入！");
                                        $(".msg").css("color","darkred");
                                    }
                                });
                            }else{
                                vcode = false;
                                vo.refresh();
                                $(".msg").text("用户名或密码不正确，请重新输入！");
                                $(".msg").css("color","darkred");
                            }
                        })

                    }
                }

            })
        })
    </script>
  </head>
  <body>
    <div class="page login-page">
      <div class="container d-flex align-items-center">
        <div class="form-holder has-shadow" style="margin-top: 100px">
          <div class="row">
            <!-- Logo & Information Panel-->
            <div class="col-lg-6">
              <div class="info d-flex align-items-center">
                <div class="content"style="margin-top: 220px">
                  <div class="logo">
                    <h1 style="font-size:40px;font-weight: 600;">梳碧湖驾校预约管理系统</h1>
                  </div>
                  <p style=";font-size:16px;">欢迎登陆梳碧湖驾校, 请输入您的账号密码.</p>
                </div>
              </div>
            </div>
            <!-- Form Panel    -->
            <div class="col-lg-6 bg-white">
              <div class="form d-flex align-items-center">
                <div class="content" style="margin-top: 130px">
                  <form method="post" class="form-validate">
                    <div class="form-group" id="uid">
                      <input id="login-username" type="text" name="loginUsername" required data-msg="请输入您的账号" class="input-material">
                      <label for="login-username" class="label-material" style="font-size:16px">账号</label>
                    </div>

                    <div class="form-group" id="pwd">
                      <input id="login-password" type="password" name="loginPassword" required data-msg="请输入您的密码" class="input-material">
                      <label for="login-password" class="label-material" style="font-size:16px">密码</label>
                    </div>
                    <div class="form-group">
                      <label style="color: #aaa">验证码</label>
                      <div id="code"></div>
                    </div>
                    <!-- 身份验证-->
                    <div class="form-group"style="margin-top: 10px;color: #aaa" id="role">
                            <label style="margin-right:20px;font-size: 16px">角色</label>
                            <label style="margin-right:30px;font-size: 16px">
                                <input type="radio" name="optionsRadios" id="optionsRadios1" value="1" checked> 管理员
                            </label>

                            <label style="margin-right:30px;font-size: 16px">
                                <input type="radio" name="optionsRadios" id="optionsRadios." value="7"> 教练
                            </label>
                        </div>
                    <div class="row">
                      <a id="btnLogin" class="btn btn-primary" style="font-size:16px;font-weight: 400;">登录</a>
                      <div class="col-md-10 msg"></div>
                    </div>

                    <!-- This should be submit button but I replaced it with <a> for demo purposes-->

                  </form>

                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="copyrights text-center">

        <p style="font-size:16px">飘落晚风
        </p>
      </div>
    </div>

  </body>
</html>